package ru.rchervot.sanasar.client.view;

import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.event.dom.client.HasKeyPressHandlers;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HasValue;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;

public abstract class AbstractRecordFooterView extends Composite
	implements RecordFooterPresenter.Display {

	private final HorizontalPanel basePanel = new HorizontalPanel();
	private final HorizontalPanel rightPanel = new HorizontalPanel();
	final protected HorizontalPanel leftPanel = new HorizontalPanel();
	
	private final Button prev = new Button();
	private final Button next = new Button();
	private final TextBox itemBox = new TextBox();
	
	private Presenter presenter;
	
	public AbstractRecordFooterView() {
		super();
		
		this.initWidget(basePanel);
		basePanel.setStylePrimaryName("AbstractRecordFooterView"); // should be after initWidget()
		
		leftPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE); // should be before setCellHorizontalAlignment
		leftPanel.setStylePrimaryName("AbstractRecordFooterView_Left");
		
		itemBox.setStylePrimaryName("AbstractRecordFooterView_Item");
		
		prev.setText("‹");
		next.setText("›");
		
		prev.setEnabled(false);
		next.setEnabled(false);
		itemBox.setEnabled(false);
		
		rightPanel.setVerticalAlignment(VerticalPanel.ALIGN_MIDDLE);
		rightPanel.setStylePrimaryName("AbstractRecordFooterView_Right");
		rightPanel.add(new Label("Item:"));
		rightPanel.add(prev);
		rightPanel.add(itemBox);
		rightPanel.add(next);
		
		basePanel.setVerticalAlignment(HorizontalPanel.ALIGN_MIDDLE); // should be before setCellHorizontalAlignment
		basePanel.add(leftPanel);
		basePanel.setCellHorizontalAlignment(leftPanel, HasHorizontalAlignment.ALIGN_LEFT);
		
		basePanel.add(rightPanel);
		basePanel.setCellHorizontalAlignment(rightPanel, HasHorizontalAlignment.ALIGN_RIGHT);
		
		basePanel.setSize("100%", Constants.kRecordFooterHeight + "px");
	}
	
	@Override
	public void setPresenter(Presenter presenter) {
		this.presenter = presenter;
	}
	
	
	@Override
	public void setEnabledButtonNext(boolean enabled) {
		next.setEnabled(enabled);
	}

	@Override
	public void setEnabledButtonPrev(boolean enabled) {
		prev.setEnabled(enabled);
	}
	
	@Override
	public void setEnabledItemBox(boolean enabled) {
		itemBox.setEnabled(enabled);
	}
	
	@Override
	public HasClickHandlers getNextItemButton() {
		return next;
	}
	
	@Override
	public HasClickHandlers getPrevItemButton() {
		return prev;
	}
	
	@Override
	public HasValue<String> getItemBoxValue() {
		return itemBox;
	}
	
	@Override
	public HasKeyPressHandlers getItemBox() {
		return itemBox;
	}
}
